/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package plan;

import java.awt.Color;
import java.awt.Component;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author phucan
 */
public class TextBoxRender extends JTextField implements TableCellRenderer {

    Color bgColor;
    Border b = new CustomBorder();
    Border fb;    
    int[][] mark ;
    Map<Integer, EventType> eventTypes;

    public TextBoxRender(Map<Integer, EventType> map, int pCount) {
       // super();

        //this.setBorder(BorderFactory.createLineBorder(Color.gray,1));
        
        // this.setBackground(Color.red);
        mark = new int[pCount][8];
        setOpaque(true);
        eventTypes = map;
        fb=BorderFactory.createRaisedBevelBorder();
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if(hasFocus){
    this.setBorder(fb);
}else{
    this.setBorder(b);
}
        if (mark[row][column] > 0) {
            this.setBackground(eventTypes.get(mark[row][column]).getColor());
            this.setToolTipText("Click to view details");
        } else {
            if (row % 8 < 4) {
                this.setBackground(Color.white);
            } else {
                this.setBackground(Color.LIGHT_GRAY);
            }
            this.setToolTipText(null);
        }
        if (value == null) {
            return this;
        } else if (value instanceof String) {
            setText(value.toString());
        } else {
            setText("");
        }
        return this;
    }

    public void setBackgroundColor(Color bg) {
        this.bgColor = bg;
    }

    public void setMark(int row, int col, int value) {
        mark[row][col] = value;
    }
}
